home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / LINEconsole / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  15.3 KB  |  747 lines

  1. /* misc.c: misc routines */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/LINEconsole/RCS/misc.c,v 6.0 1991/12/18 20:26:30 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/LINEconsole/RCS/misc.c,v 6.0 1991/12/18 20:26:30 jpo Rel $
  9.  *
  10.  * $Log: misc.c,v $
  11.  * Revision 6.0  1991/12/18  20:26:30  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15. #include "console.h"
  16. #include    <pwd.h>
  17. #include     <sys/time.h>
  18.  
  19. char    *host = NULLCP, tailorfile[MAXPATHLENGTH];
  20. char    *actual_host = NULLCP;
  21. char    *username = NULLCP;
  22. int    authorised = FALSE;
  23. extern char    *cmd_argv[];
  24. extern int    cmd_argc, bypassHostQuestions, connected;
  25.  
  26. init_host()
  27. {
  28.     char    buf[BUFSIZ];
  29.     int    uid;
  30.     struct passwd *pwd;
  31.     uid = getuid();
  32.     pwd = getpwuid(uid);
  33.     username = strdup(pwd->pw_name);
  34.     strcpy(tailorfile, ".MTAconsole");
  35.     gethostname(buf, BUFSIZ);
  36.     host = strdup(buf);
  37.  
  38. }
  39.  
  40. set_host()
  41. {
  42.     int    cont = TRUE;
  43.     char    buf[BUFSIZ];
  44.     char    *password = NULLCP;
  45.     
  46.     if (bypassHostQuestions == TRUE) {
  47.         bypassHostQuestions = FALSE;
  48.         cont = FALSE;
  49.     } else if (cmd_argc > 1) {
  50.         if (host) free(host);
  51.         host = strdup(cmd_argv[1]);
  52.         cont = FALSE;
  53.     }
  54.  
  55.     while (cont == TRUE) {
  56.         fprintf(stdout, "host (%s) = ",
  57.             (host == NULLCP) ? "" : host);
  58.         fflush(stdout);
  59.         if (gets(buf) == NULL)
  60.             exit (OK);
  61.         compress(buf, buf);
  62.         if (emptyStr(buf)) {
  63.             if (host == NULL)
  64.                 fprintf(stdout, "no host set\n");
  65.             else 
  66.                 /* happy with the one we've got */
  67.                 cont = FALSE;
  68.         } else {
  69.             if (host) free(host);
  70.             host = strdup(buf);
  71.             cont = FALSE;
  72.         }
  73.     }
  74.  
  75.     if (authorised == TRUE) {
  76.         if (password) free(password);
  77.         password = strdup(getpassword("password = "));
  78.     }
  79.     fillin_passwdpep(username, password, authorised);
  80.     if (password) free(password);
  81. }
  82.  
  83. extern char    *Qversion, *Qinformation;
  84.  
  85. set_authmode (acc)
  86. struct AcSAPconnect       *acc;
  87. {
  88.     struct type_Qmgr_BindResult    *br;
  89.     
  90.     br = NULL;
  91.     authorised = FALSE;
  92.     if (Qversion != NULLCP) {
  93.         free(Qversion);
  94.         Qversion = NULLCP;
  95.     }
  96.     if (Qinformation != NULLCP) {
  97.         free (Qinformation);
  98.         Qinformation = NULLCP;
  99.     }
  100.  
  101.     if (acc->acc_ninfo >= 1) {
  102.         if (decode_Qmgr_BindResult (acc->acc_info[0], 1,
  103.                         NULLVP, NULLIP, &br) == NOTOK) 
  104.             PP_LOG(LLOG_EXCEPTIONS, ("failed to parse connect data [%s]",
  105.                          PY_pepy));
  106.         else {
  107.             switch (br->result) {
  108.                 case int_Qmgr_result_acceptedFullAccess:
  109.                 authorised = TRUE;
  110.                 break;
  111.                 case int_Qmgr_result_acceptedLimitedAccess:
  112.                 default:
  113.                 authorised = FALSE;
  114.                 break;
  115.             }
  116.             if (br -> information != NULL) 
  117.                 Qinformation = qb2str (br -> information);
  118.  
  119.             if (br -> version != NULL) 
  120.                 Qversion = qb2str (br -> version);
  121.  
  122.             free_Qmgr_BindResult(br);
  123.         }
  124.     }
  125. }
  126.  
  127. /*   */
  128.  
  129. int    uk_order = 0;
  130.  
  131. char    *
  132. reverse_adr(adr)
  133. char    *adr;
  134. {
  135.     extern char    *rindex();
  136.  
  137.     char    *ret = malloc(strlen(adr) + 1), savech;
  138.     char    *ix = adr, *iy = ret, *dom_end, *cix, *last, *dot;
  139.     int    cont;
  140.     while (*ix != '\0') {
  141.         switch (*ix) {
  142.             case '@':
  143.             case '%':
  144.             /* start of domain so reverse */
  145.             *iy++ = *ix++;
  146.             dom_end = ix;
  147.             cont = TRUE;
  148.             while (*dom_end != '\0'
  149.                    && cont == TRUE) {
  150.                 switch(*dom_end) {
  151.                     case ',':
  152.                     case ':':
  153.                     cont = FALSE;
  154.                     break;
  155.                     default:
  156.                     dom_end++;
  157.                     break;
  158.                 }
  159.             }
  160.             /* domain stretches from ix -> dom_end */
  161.  
  162.             last = dom_end;
  163.             while (last != ix) {
  164.                 savech = *last;
  165.                 *last = '\0';
  166.                 if ((dot = rindex(ix, '.')) == NULLCP) {
  167.                     dot = ix;
  168.                     cix =  dot;
  169.                 } else 
  170.                     cix = dot + 1;
  171.                 *last = savech;
  172.                 do 
  173.                 {
  174.                     *iy++ = *cix++;
  175.                 } while (cix != last);
  176.                 
  177.                 if (dot != ix) {
  178.                     *iy++ = '.';
  179.                     last = dot;
  180.                 } else
  181.                     last = ix;
  182.             }
  183.             ix = dom_end;
  184.             break;
  185.                 
  186.             default:            
  187.             *iy++ = *ix++;
  188.             break;
  189.         }
  190.     }
  191.     *iy = '\0';
  192.     return ret;
  193. }
  194.  
  195. char    *
  196. reverse_mta(mta)
  197. char    *mta;
  198. {
  199.     extern    char    *index();
  200.     char *adr, *ret, *ix;
  201.     char    buf[BUFSIZ];
  202.     (void) sprintf(buf, "foo@%s", mta);
  203.     ret = reverse_adr(buf);
  204.     ix = index (ret, '@');
  205.     adr = strdup(++ix);
  206.     free(ret);
  207.     return adr;
  208. }
  209.  
  210. resize_info_str(pold, poldlen, inc)
  211. char        **pold;
  212. int        *poldlen,
  213.         inc;
  214. {
  215.     if ((int)strlen(*pold) + inc >= *poldlen) {
  216.         *poldlen += BUFSIZ;
  217.         *pold = realloc(*pold, (unsigned) *poldlen);
  218.     }
  219. }
  220.  
  221. char    *time_t2RFC(in)
  222. time_t    in;
  223. {
  224.     char    buf[BUFSIZ];
  225.     struct tm *tm;
  226.     struct UTCtime uts;
  227. #ifdef SVR4
  228.     extern long timezone;
  229. #else
  230.     struct timeval dummy;
  231.     struct timezone time_zone;
  232. #endif
  233.     
  234.     tm = localtime (&in);
  235.     tm2ut (tm, &uts);
  236.     uts.ut_flags |= UT_ZONE;
  237. #ifdef SVR4
  238.     uts.ut_zone = timezone / 60;
  239. #else
  240.     gettimeofday(&dummy, &time_zone);
  241.     uts.ut_zone = time_zone.tz_minuteswest;
  242. #endif
  243.     UTC2rfc(&uts, buf);
  244.     return strdup(buf);
  245. }
  246.  
  247. /* convert number to volume */
  248.  
  249. char    *vol2str(vol)
  250. int    vol;
  251. {
  252.     char    buf[BUFSIZ];
  253.  
  254.     if (vol < 1024)
  255.         sprintf(buf, "%d bytes", vol);
  256.     else if (vol < 1048576)
  257.         sprintf(buf, "%d Kbytes", (vol/1024));
  258.     else 
  259.         sprintf(buf, "%d Mbytes", (vol/1048576));
  260.     return strdup(buf);
  261. }
  262.  
  263. char    *time_t2str(in)
  264. time_t  in;
  265. {
  266.     char    buf[BUFSIZ];
  267.     time_t    result;
  268.     buf[0] = '\0';
  269.     
  270.     if (in < 0)
  271.         return strdup("still in the womb");
  272.  
  273.     if ((result = in / (60 * 60 * 24)) != 0) {
  274.         sprintf(buf, "%d day%s",
  275.             result,
  276.             (result == 1) ? "" : "s");
  277.         in = in % (60 * 60 * 24);
  278.     }
  279.  
  280.     if ((result = in / (60 * 60)) != 0) {
  281.         sprintf(buf, 
  282.             (buf[0] == '\0') ? "%s%d hr%s" : "%s %d hr%s",
  283.             buf, 
  284.             result,
  285.             (result == 1) ? "" : "s");
  286.         in = in % (60 * 60);
  287.     }
  288.     if ((result = in / 60) != 0) {
  289.         sprintf(buf, 
  290.             (buf[0] == '\0') ? "%s%d min%s" : "%s %d min%s",
  291.             buf, 
  292.             result,
  293.             (result == 1) ? "" : "s");
  294.         in = in % 60;
  295.     }
  296.  
  297.     if (buf[0] == '\0' && in != 0)
  298.         sprintf(buf, "%d sec%s", 
  299.             in,
  300.             (in == 1) ? "" : "s");
  301.     if (buf[0] == '\0')
  302.         sprintf(buf, "just born");
  303.     return strdup(buf);
  304. }
  305.  
  306. #define MaxCharPerInt 16
  307.  
  308. /* convert integer to string */
  309. char    *itoa(i)
  310. int     i;
  311. {
  312.     char     buf[MaxCharPerInt];
  313.  
  314.     sprintf(buf,"%d",i);
  315.     
  316.     return strdup(buf);
  317.     
  318. }
  319.  
  320. num2unit(num, buf)
  321. int    num;
  322. char    *buf;
  323. {
  324.     if (num > 1000000)
  325.         (void) sprintf(buf, "%.2f M", 
  326.                    (double) num / 1000000.0);
  327.     else if (num > 1000)
  328.         (void) sprintf(buf, "%.2f k", 
  329.                    (double) num / 1000.0);
  330.     else
  331.         (void) sprintf(buf, "%d", num);
  332. }
  333.  
  334. time_t parsetime(s)
  335. char    *s;
  336. {
  337.     int    n;
  338.     if (s == NULLCP || *s == NULL) return 0;
  339.     while(*s != NULL && isspace(*s)) s++;
  340.     n = 0;
  341.     while (*s != NULL && isdigit(*s)) {
  342.         n = n * 10 + *s - '0';
  343.         s++;
  344.     }
  345.     while (*s != NULL && isspace(*s)) s++;
  346.     if (*s != NULL && isalpha(*s)) {
  347.         switch (*s) {
  348.             case 's':
  349.             case 'S': 
  350.             break;
  351.             case 'm': 
  352.             case 'M':
  353.             n *= 60; 
  354.             break;
  355.             case 'h':
  356.             case 'H':
  357.             n *= 3600; 
  358.             break;
  359.             case 'd': 
  360.             case 'D':
  361.             n *= 86400; 
  362.             break;
  363.             case 'w':
  364.             case 'W':
  365.             n *= 604800;
  366.             break;
  367.             default:
  368.             break;
  369.         }
  370.         return n + parsetime(s+1);
  371.     }
  372.     else return n + parsetime(s);
  373. }
  374.  
  375. char *mystrtotime(str)
  376. char    *str;
  377. {
  378.     UTC    utc;
  379.     time_t    newsecs;
  380.     time_t     current;
  381.     char    *retval;
  382.  
  383.     newsecs = parsetime(str);
  384.     time(¤t);
  385.     
  386.     current += newsecs;
  387.         
  388.     utc = time_t2utc(current);
  389.  
  390.     retval = utct2str(utc);
  391.     free((char *) utc);
  392.     return strdup(retval);
  393. }
  394.  
  395. char *lowerfy (s)
  396. char    *s;
  397. {
  398.     static char    buf[BUFSIZ];
  399.     char    *cp;
  400.  
  401.     for (cp = buf; *s; s++)
  402.         if (isascii (*s) && isupper (*s))
  403.             *cp++ = tolower (*s);
  404.         else
  405.             *cp ++ = *s;
  406.     *cp = NULL;
  407.     return buf;
  408. }
  409.  
  410. emptyStr(buf)
  411. char    *buf;
  412. {
  413.     return (isspace(buf[0]) || buf[0] == '\0');
  414. }
  415.  
  416. /*   */
  417.  
  418. /* ARGSUSED */
  419. int do_quecontrol (ad, ds, args, arg)
  420. int            ad;
  421. struct client_dispatch    *ds;
  422. int            args;
  423. struct type_Qmgr_QMGROp **arg;
  424. {
  425.     *arg = (struct type_Qmgr_QMGROp *) malloc(sizeof(**arg));
  426.     (*arg)->parm = args;
  427.     return OK;
  428. }
  429.  
  430. /* ARGSUSED */
  431. int quecontrol_result (ad, id, dummy, result, roi)
  432. int    ad,
  433.     id,
  434.     dummy;
  435. struct type_Qmgr_Pseudo__qmgrControl    *result;
  436. struct RoSAPindication            *roi;
  437. {
  438.     return OK;
  439. }
  440.  
  441. static CMD_TABLE    tb_controls [] = { /* quecontrol options */
  442.     "abort",        int_Qmgr_QMGROp_abort,
  443.     "abor",            int_Qmgr_QMGROp_abort,
  444.     "abo",            int_Qmgr_QMGROp_abort,
  445.     "ab",            int_Qmgr_QMGROp_abort,
  446.     "a",            int_Qmgr_QMGROp_abort,
  447.  
  448.     "decreasemaxchans",    int_Qmgr_QMGROp_decreasemaxchans,
  449.     "decreasemaxchan",    int_Qmgr_QMGROp_decreasemaxchans,
  450.     "decreasemaxcha",    int_Qmgr_QMGROp_decreasemaxchans,
  451.     "decreasemaxch",    int_Qmgr_QMGROp_decreasemaxchans,
  452.     "decreasemaxc",        int_Qmgr_QMGROp_decreasemaxchans,
  453.     "decreasemax",        int_Qmgr_QMGROp_decreasemaxchans,
  454.     "decreasema",        int_Qmgr_QMGROp_decreasemaxchans,
  455.     "decreasem",        int_Qmgr_QMGROp_decreasemaxchans,
  456.     "decrease",        int_Qmgr_QMGROp_decreasemaxchans,
  457.     "decreas",        int_Qmgr_QMGROp_decreasemaxchans,
  458.     "decrea",        int_Qmgr_QMGROp_decreasemaxchans,
  459.     "decre",        int_Qmgr_QMGROp_decreasemaxchans,
  460.     "decr",            int_Qmgr_QMGROp_decreasemaxchans,
  461.     "dec",            int_Qmgr_QMGROp_decreasemaxchans,
  462.     "de",            int_Qmgr_QMGROp_decreasemaxchans,
  463.  
  464.     "disableAll",        int_Qmgr_QMGROp_disableAll,
  465.     "disableAl",        int_Qmgr_QMGROp_disableAll,
  466.     "disableA",        int_Qmgr_QMGROp_disableAll,
  467.  
  468.     "disableSubmission",     int_Qmgr_QMGROp_disableSubmission,
  469.     "disableSubmissio",     int_Qmgr_QMGROp_disableSubmission,
  470.     "disableSubmissi",     int_Qmgr_QMGROp_disableSubmission,
  471.     "disableSubmiss",     int_Qmgr_QMGROp_disableSubmission,
  472.     "disableSubmis",     int_Qmgr_QMGROp_disableSubmission,
  473.     "disableSubmi",     int_Qmgr_QMGROp_disableSubmission,
  474.     "disableSubm",         int_Qmgr_QMGROp_disableSubmission,
  475.     "disableSub",         int_Qmgr_QMGROp_disableSubmission,
  476.     "disableSu",         int_Qmgr_QMGROp_disableSubmission,
  477.     "disableS",         int_Qmgr_QMGROp_disableSubmission,
  478.  
  479.     "enableAll",        int_Qmgr_QMGROp_enableAll,
  480.     "enableAl",        int_Qmgr_QMGROp_enableAll,
  481.     "enableA",        int_Qmgr_QMGROp_enableAll,
  482.  
  483.     "enableSubmission",    int_Qmgr_QMGROp_enableSubmission,
  484.     "enableSubmissio",    int_Qmgr_QMGROp_enableSubmission,
  485.     "enableSubmissi",    int_Qmgr_QMGROp_enableSubmission,
  486.     "enableSubmiss",    int_Qmgr_QMGROp_enableSubmission,
  487.     "enableSubmis",        int_Qmgr_QMGROp_enableSubmission,
  488.     "enableSubmi",        int_Qmgr_QMGROp_enableSubmission,
  489.     "enableSubm",        int_Qmgr_QMGROp_enableSubmission,
  490.     "enableSub",        int_Qmgr_QMGROp_enableSubmission,
  491.     "enableSu",        int_Qmgr_QMGROp_enableSubmission,
  492.     "enableS",        int_Qmgr_QMGROp_enableSubmission,
  493.  
  494.     "increasemaxchans",    int_Qmgr_QMGROp_increasemaxchans,
  495.     "increasemaxchan",    int_Qmgr_QMGROp_increasemaxchans,
  496.     "increasemaxcha",    int_Qmgr_QMGROp_increasemaxchans,
  497.     "increasemaxch",    int_Qmgr_QMGROp_increasemaxchans,
  498.     "increasemaxc",        int_Qmgr_QMGROp_increasemaxchans,
  499.     "increasemax",        int_Qmgr_QMGROp_increasemaxchans,
  500.     "increasema",        int_Qmgr_QMGROp_increasemaxchans,
  501.     "increasem",        int_Qmgr_QMGROp_increasemaxchans,
  502.     "increase",        int_Qmgr_QMGROp_increasemaxchans,
  503.     "increas",        int_Qmgr_QMGROp_increasemaxchans,
  504.     "increa",        int_Qmgr_QMGROp_increasemaxchans,
  505.     "incre",        int_Qmgr_QMGROp_increasemaxchans,
  506.     "incr",            int_Qmgr_QMGROp_increasemaxchans,
  507.     "inc",            int_Qmgr_QMGROp_increasemaxchans,
  508.     "in",            int_Qmgr_QMGROp_increasemaxchans,
  509.     "i",            int_Qmgr_QMGROp_increasemaxchans,
  510.  
  511.     "rereadQueue",        int_Qmgr_QMGROp_rereadQueue,
  512.     "rereadQueu",        int_Qmgr_QMGROp_rereadQueue,
  513.     "rereadQue",        int_Qmgr_QMGROp_rereadQueue,
  514.     "rereadQu",        int_Qmgr_QMGROp_rereadQueue,
  515.     "rereadQ",        int_Qmgr_QMGROp_rereadQueue,
  516.     "reread",        int_Qmgr_QMGROp_rereadQueue,
  517.     "rerea",        int_Qmgr_QMGROp_rereadQueue,
  518.     "rere",            int_Qmgr_QMGROp_rereadQueue,
  519.     "rer",            int_Qmgr_QMGROp_rereadQueue,
  520.  
  521.  
  522.     "restart",        int_Qmgr_QMGROp_restart,
  523.     "restar",        int_Qmgr_QMGROp_restart,
  524.     "resta",        int_Qmgr_QMGROp_restart,
  525.     "rest",            int_Qmgr_QMGROp_restart,
  526.     "res",            int_Qmgr_QMGROp_restart,
  527.  
  528.     "terminate",        int_Qmgr_QMGROp_gracefulTerminate,
  529.     "terminat",        int_Qmgr_QMGROp_gracefulTerminate,
  530.     "termina",        int_Qmgr_QMGROp_gracefulTerminate,
  531.     "termin",        int_Qmgr_QMGROp_gracefulTerminate,
  532.     "termi",        int_Qmgr_QMGROp_gracefulTerminate,
  533.     "term",            int_Qmgr_QMGROp_gracefulTerminate,
  534.     "ter",            int_Qmgr_QMGROp_gracefulTerminate,
  535.     "te",            int_Qmgr_QMGROp_gracefulTerminate,
  536.     "t",            int_Qmgr_QMGROp_gracefulTerminate,
  537.  
  538.     0,        -1
  539.     };
  540.  
  541.  
  542. static int str2control(str)
  543. char    *str;
  544. {
  545.     Command    ret;
  546.     char    *ix = str, savech, *start;
  547.     
  548.     while (*ix != '\0' && isspace(*ix)) ix++;
  549.     start = ix;
  550.     while (*ix != '\0' && !isspace(*ix)) ix++;
  551.     savech = *ix;
  552.     *ix = '\0';
  553.     
  554.     ret = (Command) cmd_srch(start, tb_controls);
  555.     *ix = savech;
  556.     return ret;
  557. }
  558.  
  559. static int control_options()
  560. {
  561.     fprintf(stdout,
  562.         "Qmgr Controls available are:");
  563.     fprintf(stdout,
  564.         "abort, terminate, restart, rereadQueue,\n\tdisableSubmission, enableSubmission, disableAll, enableAll, increasemaxchans, and decreasemaxchans\n");
  565. }
  566.  
  567. static int get_control(pcontrol)
  568. int    *pcontrol;
  569. {
  570.     int    cont = TRUE, first = TRUE;
  571.     int    ret = NOTOK, control;
  572.     char    buf[BUFSIZ];
  573.  
  574.     while (cont == TRUE) {
  575.         if (cmd_argc > 1 && first == TRUE) {
  576.             strcpy(buf, cmd_argv[1]);
  577.             first = FALSE;
  578.         } else {
  579.             fprintf(stdout, "quecontrol (q=quit)> ");
  580.             fflush (stdout);
  581.         
  582.             if (gets(buf) == NULL)
  583.                 exit(OK);
  584.         }
  585.         compress(buf, buf);
  586.         
  587.         if (buf[0] == 'q') {
  588.             /* use same command as before */
  589.             cont = FALSE;
  590.         } else if ((control = str2control(buf)) < 0) {
  591.             fprintf(stdout,
  592.                 "Unknown control '%s'\n", buf);
  593.             control_options();
  594.         } else {
  595.             *pcontrol = control;
  596.             cont = FALSE;
  597.             ret = OK;
  598.         }
  599.     }
  600.  
  601.     return ret;
  602. }
  603.  
  604. Qcontrol()
  605. {
  606.     int    control;
  607.     
  608.     if (get_control(&control) == OK) 
  609.         my_invoke(quecontrol, (char **) control);
  610. }
  611.  
  612. extern char    *pager;
  613. extern int    pageron;
  614.  
  615. #define PAGER    1
  616. #define TAILORFILE     2
  617. #define AUTHORISED    3
  618. #define USER        4
  619.  
  620. static CMD_TABLE    tb_variables [] = { /* line console variables */
  621.     "pager",    PAGER,
  622.     "tailorfile",    TAILORFILE,
  623.     "authorised",    AUTHORISED,
  624.     "user",        USER,
  625.     0,         -1
  626.     };
  627.  
  628. print_variables()
  629. {
  630.     if (pager) {
  631.         fprintf(stdout,
  632.             "pager='%s' (%s)\n",
  633.             pager,
  634.             (pageron == TRUE) ? "on" : "off");
  635.     } else
  636.         fprintf(stdout,
  637.             "no pager set\n");
  638.     if (tailorfile[0] != '\0')
  639.         fprintf(stdout,
  640.             "tailorfile='%s'\n",
  641.             tailorfile);
  642.     else
  643.         fprintf(stdout,
  644.             "no tailorfile set\n");
  645.  
  646.     fprintf(stdout,
  647.         "authorised=%s\n",
  648.         (authorised == TRUE) ? "yes" : "no");
  649.     fprintf(stdout,
  650.         "user='%s'\n",
  651.         username);
  652. }
  653.  
  654. str2variable(str)
  655. char    *str;
  656. {
  657.     return cmd_srch(str, tb_variables);
  658. }
  659.  
  660. variables()
  661. {
  662.     if (cmd_argc > 1) {
  663.         int i;
  664.         char    *ix;
  665.         for (i = 1; i < cmd_argc; i++) {
  666.             if ((ix = index(cmd_argv[i], '=')) == NULLCP) 
  667.                 fprintf(stderr,
  668.                     "unable to parse '%s' as variable=value\n",
  669.                     cmd_argv[i]);
  670.             else {
  671.                 *ix = '\0';
  672.                 switch (str2variable(cmd_argv[i])) {
  673.                     case PAGER:
  674.                     *ix++ = '=';
  675.                     if (*ix == '\0'
  676.                         || lexequ(ix, "-") == 0) {
  677.                         if (pager) free(pager);
  678.                         pager = NULLCP;
  679.                     } else if (lexequ(ix, "on") == 0)
  680.                         pageron = TRUE;
  681.                     else if (lexequ(ix, "off") == 0)
  682.                         pageron = FALSE;
  683.                     else {
  684.                         if (pager) free(pager);
  685.                         pager = strdup(ix);
  686.                     }
  687.                     break;
  688.  
  689.                     case TAILORFILE:
  690.                     if (connected == TRUE) 
  691.                         fprintf(stderr,
  692.                             "cannot change tailorfile while connected\n");
  693.                     else {
  694.                         *ix++ = '=';
  695.                         strcpy(tailorfile, ix);
  696.                     } 
  697.                     break;
  698.  
  699.                     case USER:
  700.                     if (connected == TRUE)
  701.                         fprintf(stderr,
  702.                             "cannot change username while connected\n");
  703.                     else {
  704.                         *ix++ = '=';
  705.                         if (username) free(username);
  706.                         username = strdup(ix);
  707.                     }
  708.                     break;
  709.  
  710.                     case AUTHORISED:
  711.                     *ix++ = '=';
  712.                     switch(*ix) {
  713.                         case 'y':
  714.                         case 'Y':
  715.                         if (connected == TRUE)
  716.                             fprintf(stderr,
  717.                                 "cannot turn authorised while connected\n");
  718.                         else 
  719.                             authorised = TRUE;
  720.                         break;
  721.                         case 'n':
  722.                         case 'N':
  723.                         authorised = FALSE;
  724.                         break;
  725.                         default:
  726.                         fprintf(stdout, 
  727.                             "Don't recognise boolean value '%s'\n",
  728.                             ix);
  729.                     }
  730.                     break;
  731.                             
  732.                     default:
  733.                     fprintf(stderr,
  734.                         "unknown variable '%s' ",
  735.                         cmd_argv[i]);
  736.                     *ix = '=';
  737.                     fprintf(stderr,
  738.                         "in '%s'\n",
  739.                         cmd_argv[i]);
  740.                     break;
  741.                 }
  742.             }
  743.         }
  744.     }
  745.     print_variables();
  746. }
  747.